﻿using GalaSoft.MvvmLight;
using System;

namespace mal.WP7.GoogleAnalytics.ViewModels.Dashboard
{
    public class DashboardRowViewModel : ViewModelBase
    {
        #region Fields
        private string websiteId;
        private string websiteName;
        private double currentValue;
        private double previousValue;
        private double? progressPercent;   
        #endregion

        #region Construction / Destruction

        #endregion

        #region enum, struct, class

        #endregion

        #region Properties
        public double PreviousValue
        {
            get
            {
                return this.previousValue;
            }

            set
            {
                if (this.previousValue != value)
                {
                    this.previousValue = value;
                    RaisePropertyChanged("PreviousValue");
                    this.SetProgressPercent();
                }
            }
        }

        public double CurrentValue
        {
            get
            {
                return this.currentValue;
            }

            set
            {
                if (this.currentValue != value)
                {
                    this.currentValue = value;
                    RaisePropertyChanged("CurrentValue");
                    this.SetProgressPercent();
                }
            }
        }

        public string WebsiteName
        {
            get
            {
                return this.websiteName;
            }

            set
            {
                if (this.websiteName != value)
                {
                    this.websiteName = value;
                    RaisePropertyChanged("WebsiteName");
                }
            }
        }

        public string WebsiteId
        {
            get
            {
                return this.websiteId;
            }

            set
            {
                if (this.websiteId != value)
                {
                    this.websiteId = value;
                    RaisePropertyChanged("WebsiteId");
                }
            }
        }

        public double? ProgressPercent
        {
            get
            {
                return this.progressPercent;
            }

            set
            {
                if (this.progressPercent != value)
                {
                    this.progressPercent = value;

                    RaisePropertyChanged("ProgressPercent");
                }
            }
        }
        #endregion

        #region Methods
        private void SetProgressPercent()
        {
            if (this.PreviousValue != 0)
            {
                this.ProgressPercent = 100 * (this.CurrentValue - this.PreviousValue) / this.PreviousValue;                
            }
        }
        #endregion

        #region Events

        #endregion
    }
}
